package com.tianji.learning.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.tianji.common.exceptions.BizIllegalException;
import com.tianji.learning.domain.po.PointsBoardSeason;
import com.tianji.learning.mapper.PointsBoardSeasonMapper;
import com.tianji.learning.service.IPointsBoardSeasonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 刘慧
 * @since 2024-07-03
 */
@Service
public class PointsBoardSeasonServiceImpl extends ServiceImpl<PointsBoardSeasonMapper, PointsBoardSeason> implements IPointsBoardSeasonService {

    @Override
    public Integer querySeasonByTime(LocalDateTime time) {
        //根据时间查询赛季
        //大于等于，开始时间  小于等于结束时间
        PointsBoardSeason season = lambdaQuery()
                .ge(PointsBoardSeason::getBeginTime, time)
                .le(PointsBoardSeason::getEndTime, time)
                .one();
        if (ObjectUtil.isEmpty(season)){
            log.error("赛季信息不存在");
            throw  new BizIllegalException("赛季信息不存在");
        }
   return season.getId();

    }
}
